package com.loocan.answer

import android.animation.AnimatorSet
import android.animation.ObjectAnimator
import android.content.Intent
import android.os.Bundle
import android.view.animation.AnticipateOvershootInterpolator
import androidx.appcompat.app.AppCompatActivity
import com.loocan.answer.databinding.ActivitySplashBinding
import com.leyou.sdk.ads.AdSdk
import com.leyou.sdk.ads.api.SplashAd
import com.leyou.sdk.ads.config.AdCode
import com.leyou.sdk.ads.interfaces.FusionAdNative
import com.loocan.answer.utils.CommonUtil
import com.loocan.answer.utils.SoundPlayer
import com.loocan.answer.utils.StatusBarUtils

/**
 * @author liupeng QQ:806875201
 * @time 2025/6/14 20:59
 * @Description  describe
 */

class FirstActivity : AppCompatActivity() {
    private lateinit var binding: ActivitySplashBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivitySplashBinding.inflate(layoutInflater)
        setContentView(binding.root)

        StatusBarUtils.setStatusTransparent(this)

        initGameButtonEffect()
        initData()
    }

    private fun initData() {
        SoundPlayer.initialize( this)
        // 加载声音文件
        SoundPlayer.loadSound(this, R.raw.click_sound);

        binding.tvNext.setOnClickListener {
            SoundPlayer.playSound()
            startActivity(Intent(this@FirstActivity, MainActivity::class.java))
            finish()
        }
    }

    private fun initGameButtonEffect() {
        binding.tvNext.apply {
            setOnTouchListener { v, event ->
                when(event.action) {
                    android.view.MotionEvent.ACTION_DOWN -> {
                        // 缩放动画
                        ObjectAnimator.ofFloat(v, "scaleX", 1f, 0.95f).apply {
                            duration = 100
                            start()
                        }
                        ObjectAnimator.ofFloat(v, "scaleY", 1f, 0.95f).apply {
                            duration = 100
                            start()
                        }
                        // 阴影位移
                        v.translationZ = 8f
                    }
                    android.view.MotionEvent.ACTION_UP,
                    android.view.MotionEvent.ACTION_CANCEL -> {
                        // 弹性恢复动画
                        val animatorSet = AnimatorSet()
                        animatorSet.playTogether(
                            ObjectAnimator.ofFloat(v, "scaleX", 0.95f, 1f).apply {
                                interpolator = AnticipateOvershootInterpolator()
                            },
                            ObjectAnimator.ofFloat(v, "scaleY", 0.95f, 1f).apply {
                                interpolator = AnticipateOvershootInterpolator()
                            }
                        )
                        animatorSet.duration = 200
                        animatorSet.start()
                        v.translationZ = 0f
                    }
                }
                false
            }
        }
    }
}